; Copyright 2013 padnest@gmail.com

; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;   http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.


	LIST p=18F4431
	#include <p18f4431.inc>
    #include pic18f-langext-v1.2.inc


; configs
	CONFIG OSC = HS
	CONFIG IESO = OFF
	CONFIG FCMEN = OFF
	CONFIG PWRTEN = ON
	CONFIG WDTEN = OFF
	CONFIG BOREN = OFF
	CONFIG MCLRE = ON
	CONFIG LVP = OFF
	CONFIG DEBUG = OFF
	CONFIG STVREN = ON

; registers
	UDATA
REGX		res 1
REGH		res 1
REGL    	res 1

; reset vector
	ORG	0x0000
	goto	main

; interrupt vector in compatibility mode
	ORG	0x0008

main:

	movlf	0x01, REGL
	movlf	0x00, REGH
	decf	REGL, F
	btfss	STATUS, C
	decf	REGH, F

	decf	REGL, F
	btfss	STATUS, C
	decf	REGH, F



    ; test andlf
    movlf 0x33, REGX
    andlf 0xF0, REGX, F     ; result: REGX=0x30 W=0xF0
    movlf 0x33, REGX
    andlf 0xF0, REGX, W     ; result: REGX=0x33 W=0x30

    ; test cmplf
    movlf 0x33, REGX
    cmplf 0x33, REGX        ; freg=lit -> N=0 Z=1 C=0 (STATUS=0000 0111)
    cmplf 0x34, REGX        ; freg<lit -> N=1 Z=0 C=0 (STATUS=0001 0000)
    cmplf 0x32, REGX        ; freg>lit -> N=0 Z=0 C=1 (STATUS=0000 0011)

	; test dec16f
	movlf	0x01, REGL
	movlf	0x01, REGH
	dec16f	REGL, REGH		; result: REGL=0x00 REGH=0x01 (STATUS=0000 0111)
	dec16f	REGL, REGH		; result: REGL=0xFF REGH=0x00 (STATUS=0000 0111)
	movlf	0x00, REGL
	movlf	0x00, REGH
	dec16f	REGL, REGH		; result: REGL=0xFF REGH=0xFF (STATUS=0001 0000)

	; test inc16f
	movlf	0xFE, REGL
	movlf	0x00, REGH
	bcf		STATUS, C
	inc16f	REGL, REGH		; result: REGL=0xFF REGH=0x00 (STATUS=000X 00XX)
	inc16f	REGL, REGH		; result: REGL=0x00 REGH=0x01 (STATUS=0000 0000)
	movlf	0xFF, REGL
	movlf	0xFF, REGH
	bcf		STATUS, C
	inc16f	REGL, REGH		; result: REGL=0x00 REGH=0x00 (STATUS=0000 0111)

    ; test iorlf
    movlf 0x20, REGX
    iorlf 0x13, REGX, F     ; result: REGX=0x33 W=0x13
    movlf 0x20, REGX
    iorlf 0x13, REGX, W     ; result: REGX=0x20 W=0x33

    ; test shftlf
    movlf b'10101010', REGX
    shftlf REGX, 1          ; result: REGX=0101 0100
    movlf b'10101010', REGX
    shftlf REGX, 2          ; result: REGX=1010 1000
    movlf b'10101010', REGX
    shftlf REGX, 3          ; result: REGX=0101 0000
    movlf b'10101010', REGX
    shftlf REGX, 4          ; result: REGX=1010 0000
    movlf b'10101010', REGX
    shftlf REGX, 5          ; result: REGX=0100 0000
    movlf b'10101010', REGX
    shftlf REGX, 6          ; result: REGX=1000 0000
    movlf b'00000001', REGX
    shftlf REGX, 7          ; result: REGX=1000 0000

    ; test shftrf
    movlf b'10101010', REGX
    shftrf REGX, 1          ; result: REGX=0101 0101
    movlf b'10101010', REGX
    shftrf REGX, 2          ; result: REGX=0010 1010
    movlf b'10101010', REGX
    shftrf REGX, 3          ; result: REGX=0001 0101
    movlf b'10101010', REGX
    shftrf REGX, 4          ; result: REGX=0000 1010
    movlf b'10101010', REGX
    shftrf REGX, 5          ; result: REGX=0000 0101
    movlf b'10101010', REGX
    shftrf REGX, 6          ; result: REGX=0000 0010
    movlf b'10101010', REGX
    shftrf REGX, 7          ; result: REGX=0000 0001

    ; test xorlf
    movlf 0x33, REGX
    xorlf 0xFF, REGX, F     ; result: REGX=0xCC W=0xFF

    movlf 0x33, REGX
    xorlf 0xFF, REGX, W     ; result: REGX=0x33 W=0xCC


loop8:							; infinite loop
	goto	loop8

	END


